package com.uchengwang.ui.utils;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 */
public class CheckUtil {
	private CheckUtil(){}

	private static CheckUtil checker;

	public static CheckUtil getChecker() {
		if (checker == null){
			checker = new CheckUtil();
		}
		return checker;
	}

	private String phone = "^[1]{1}[1,2,3,4,5,6,7,8,9]{1}[0-9]{9}";

	public boolean checkTelNum(String mobPhnNum) {
		if(TextUtils.isEmpty(mobPhnNum)) return false;
		// 判断手机号码是否是11位
		if (mobPhnNum.length() == 11) {
			if (mobPhnNum.matches(phone)){
				return true;
			}
			return false;

		}
		return false;
	}
	
	/**
	  * 验证邮箱地址是否正确
	  * @param email
	  * @return
	  */
	public boolean checkEmail(String email) {
		if(TextUtils.isEmpty(email)) return false;
		String check = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{1,5}";
		boolean flag = email.matches(check);
		return flag;
	}
	
	public boolean checkVerfiy(String verfiy){
		if(TextUtils.isEmpty(verfiy)) return false;
		boolean flag = true;
		
		return flag;
	}
	
	// 6-16位,必须字母数字组合
	public boolean checkPwd(String pwd){
		if(TextUtils.isEmpty(pwd)) return false;
		
		boolean flag = false;
		try {
			String check = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";
			Pattern regex = Pattern.compile(check);
			Matcher matcher = regex.matcher(pwd);
			flag = matcher.matches();
		} catch (Exception e) {
			flag = false;
		}
		
		return flag;
	}
	
	public boolean checkUUID(long uuid){
		if(uuid > 0) return true;
		return false;
	}
	
	public boolean checkUUID(String uuid){
		if(TextUtils.isEmpty(uuid)) return false;
		try{
			long id = Long.valueOf(uuid);
			return checkUUID(id);
		}catch(Exception e){
			return false;
		}
	}

	public boolean checkUBaId(String ubaId){
		if (TextUtils.isEmpty(ubaId)){
			return false;
		}
		if (ubaId.matches("^[a-zA-Z][0-9a-zA-Z_]{3,19}")){
			return true;
		}
		return false;
	}
}
